<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	int i = 1;
	session.getAttribute("logoner");
	session.getAttribute("allBookList");
%>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>图书管理系统</title>
<style>
.card .table td, .card .table th {
	text-align: center;
}

.dropdown-item a:link {
	color: #000;
}

.dropdown-item a:visited {
	color: #000;
}
</style>
<!--favicon-->
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<!-- simplebar CSS-->
<link href="<%=basePath%>css/simplebar.css" rel="stylesheet" />
<!-- Bootstrap core CSS-->
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
<!-- animate CSS-->
<link href="<%=basePath%>css/animate.css" rel="stylesheet"
	type="text/css" />
<!-- Icons CSS-->
<link href="<%=basePath%>css/icons.css" rel="stylesheet" type="text/css" />
<!-- Sidebar CSS-->
<link href="<%=basePath%>css/sidebar-menu.css" rel="stylesheet" />
<!-- Custom Style-->
<link href="<%=basePath%>css/app-style.css" rel="stylesheet" />
</head>

<body>
	<div id="wrapper" class="">
		<!--Start sidebar-wrapper-->
		<div id="sidebar-wrapper" data-simplebar="init"
			data-simplebar-auto-hide="true" class="active">
			<div class="simplebar-track vertical" style="visibility: visible;">
				<div class="simplebar-scrollbar"
					style="visibility: visible; top: 0px; height: 731px;"></div>
			</div>
			<div class="simplebar-track horizontal" style="visibility: hidden;">
				<div class="simplebar-scrollbar"></div>
			</div>
			<div class="simplebar-scroll-content"
				style="padding-right: 17px; margin-bottom: -34px;">
				<div class="simplebar-content"
					style="padding-bottom: 17px; margin-right: -17px;">
					<div class="brand-logo">
						<a href=<%=basePath%>> <img
							src="<%=basePath%>images/logo-icon.png" class="logo-icon"
							alt="logo icon">
							<h5 class="logo-text">图书管理系统</h5>
						</a>
					</div>
					<ul class="sidebar-menu do-nicescrol in">
						<li><a href="<%=basePath%>" class="waves-effect"> <i
								class="zmdi zmdi-view-dashboard"></i> <span> <c:if
										test="${empty logoner }">
										书籍查询
									</c:if> <c:if test="${logoner.getUserGrade() == 0}">
										书籍管理
									</c:if> <c:if test="${logoner.getUserGrade() == 1}">
										书籍查询
									</c:if>
							</span> <i class="fa fa-angle-left pull-right"></i>
						</a></li>
						<c:if test="${logoner.getUserGrade() == 0}">
							<li><a href="<%=basePath%>pages/addbook.jsp"
								class="waves-effect"> <i class="zmdi zmdi-view-dashboard"></i>
									<span>添加书籍</span> <i class="fa fa-angle-left pull-right"></i>
							</a></li>
							<li><a href="<%=basePath%>UserServlet?action=getalluser"
								class="waves-effect"> <i class="zmdi zmdi-view-dashboard"></i>
									<span>用户列表</span> <i class="fa fa-angle-left pull-right"></i>
							</a></li>
						</c:if>
						<c:if test="${not empty logoner }">
							<li><a href="<%=basePath%>BorrowServlet?action=getBorList"
								class="waves-effect"> <i class="zmdi zmdi-view-dashboard"></i>
									<span>借书详情</span> <i class="fa fa-angle-left pull-right"></i>
							</a></li>
						</c:if>
					</ul>
				</div>
			</div>
		</div>
		<!--End sidebar-wrapper-->

		<!--Start topbar header-->
		<header class="topbar-nav">
			<nav class="navbar navbar-expand fixed-top bg-white">
				<ul class="navbar-nav mr-auto align-items-center">
					<li class="nav-item"><a class="nav-link toggle-menu"
						href="javascript:void();"> <i class="icon-menu menu-icon"></i>
					</a></li>
				</ul>

				<ul class="navbar-nav align-items-center right-nav-link">
					<li class="nav-item"><c:if test="${empty logoner}">
							<a href="<%=basePath%>pages/logon.jsp"
								class="nav-link dropdown-toggle dropdown-toggle-nocaret">
								<p class="page-title">登录</p>
							</a>
						</c:if> <c:if test="${ not empty logoner}">
							<a class="nav-link dropdown-toggle dropdown-toggle-nocaret"
								data-toggle="dropdown" href="#">
								<h4 class="page-title">
									<c:if test="${empty logoner.getUserName()}">
										欢迎你，${logoner.getUserId() }
									</c:if>
									<c:if test="${not empty logoner.getUserName()}">
										欢迎你，${logoner.getUserName() }
									</c:if>
								</h4>
							</a>
							<ul class="dropdown-menu dropdown-menu-right">
								<li class="dropdown-item user-details"><a
									href="javaScript:void();">
										<div class="media">
											<div class="media-body">
												<h5 class="mt-2 user-title">ID:${logoner.getUserId()}</h5>
												<p class="user-subtitle">
													<c:if test="${empty logoner.getUserName()}">
													您没有设置您的姓名
												</c:if>
													<c:if test="${ not empty logoner.getUserName()}">
													姓名：${logoner.getUserName() }
												</c:if>
												</p>
											</div>
										</div>
								</a></li>
								<li class="dropdown-divider"></li>
								<li class="dropdown-item user-details"><a
									href="<%=basePath%>pages/updateInfo.jsp">
										<div class="media">
											<div class="media-body">
												<i class="icon-settings mr-2"></i> 修改或查看个人信息
											</div>
										</div>
								</a></li>
								<li class="dropdown-divider"></li>
								<li class="dropdown-item user-details"><a
									href="<%=basePath%>UserServlet?action=logout">
										<div class="media">
											<div class="media-body">
												<i class="icon-power mr-2"></i> 退出
											</div>
										</div>
								</a></li>
							</ul>
						</c:if>
				</ul>
			</nav>
		</header>
		<!--End topbar header-->
		<div class="clearfix"></div>

		<div class="content-wrapper">
			<div class="container-fluid">
				<!-- Breadcrumb-->
				<div class="row pt-2 pb-2">
					<div class="col-sm-9">
						<h4 class="page-title">Header Tables</h4>
					</div>
				</div>
				<!-- End Breadcrumb-->
				<div class="row">
					<div class="col-lg-12">
						<div class="card">
							<div class="card-body">
								<div class="table-responsive">
									<table class="table">
										<thead class="thead-dark">
											<tr>
												<th scope="col">#</th>
												<th scope="col">书名</th>
												<th scope="col">ISBN</th>
												<th scope="col">作者</th>
												<c:if test="${logoner.getUserGrade() == 0 }">
													<th scope="col">进价</th>
												</c:if>
												<th scope="col">售价</th>
												<th scope="col">出版时间</th>
												<th scope="col">存量</th>
												<th scope="col">操作</th>
											</tr>
										</thead>
										<tbody>
											<c:forEach items="${allBookList}" var="aai"
												varStatus="aaiStatus">
												<tr>
													<th scope="row"><%=i++%></th>
													<td>${aai.getBookName()}</td>
													<td>${aai.getBookIsbn()}</td>
													<td>${aai.getBookAuthor()}</td>
													<c:if test="${logoner.getUserGrade() == 0 }">
														<td>${aai.getBookPurchase()}
														</th>
													</c:if>
													<td>${aai.getBookPrice()}</td>
													<td>${aai.getBookPublishingTime()}</td>
													<td>${aai.getBookNum()}</td>
													<c:if test="${aai.getBookNum() <= 0}">
														<td>存量不足，无法借阅</td>
													</c:if>
													<c:if test="${aai.getBookNum() > 0}">
														<c:if test="${ empty logoner }">
															<td>未登录，无法借阅</td>
														</c:if>
														<c:if test="${ not empty logoner}">
															<c:if test="${logoner.getUserGrade() == 0 }">
																<td><a
																	href="<%=basePath%>BookServlet?action=deletebook&BookIsbn=${aai.getBookIsbn()}">删除此书</a></td>
															</c:if>
															<c:if test="${logoner.getUserGrade() == 1 }">
																<td>
																	<ul
																		style="list-style-type: none; width: 400px; margin: 0 auto;">
																		<li style="float: left; margin: 0 10px;"><a
																			href="<%=basePath%>BorrowServlet?action=borrowbook&BookIsbn=${aai.getBookIsbn()}&userid=${logoner.getUserId()}&BorrowDur=7">加入借阅单(借阅七天)</a></li>
																		<li style="float: left; margin: 0 10px;"><a
																			href="<%=basePath%>BorrowServlet?action=borrowbook&BookIsbn=${aai.getBookIsbn()}&userid=${logoner.getUserId()}&BorrowDur=30">加入借阅单(借阅30天)</a></li>
																	</ul>
																</td>
															</c:if>
														</c:if>
													</c:if>
												</tr>
											</c:forEach>
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!--End Row-->

			</div>
			<!-- End container-fluid-->

		</div>
		<!--End content-wrapper-->
		<!--Start Back To Top Button-->
		<a href="javaScript:void();" class="back-to-top"
			style="display: inline;"><i class="fa fa-angle-double-up"></i> </a>
		<!--End Back To Top Button-->
	</div>
	<!-- Bootstrap core JavaScript-->
	<script src="<%=basePath%>js/jquery.min.js"></script>
	<script src="<%=basePath%>js/popper.min.js"></script>
	<script src="<%=basePath%>js/bootstrap.min.js"></script>
	<!-- simplebar js -->
	<script src="<%=basePath%>js/simplebar.js"></script>
	<!-- waves effect js -->
	<script src="<%=basePath%>js/waves.js"></script>
	<!-- sidebar-menu js -->
	<script src="<%=basePath%>js/sidebar-menu.js"></script>
	<!-- Custom scripts -->
	<script src="<%=basePath%>js/app-script.js"></script>
</body>

</html>